<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<?php if(count($items) > 0){?>
<table cellpadding="3" cellspacing="1" width="100%">
<tr>
	<td style="background: #999;border-right:1px solid #fff;padding:5px 5px">
		<?php echo $lang['sys_money_total'].': '.number_format($summary->ad);?> VND
	</td>
	<td style="background: #999;border-right:1px solid #fff;padding:5px 5px">
		<?php echo $lang['sys_money_use'].': '.number_format($summary->sub);?> VND
	</td>
	<td style="background: #999;padding:5px 5px">
		<?php echo $lang['sys_promotion'].': '.number_format($summary->promotion)?> VND
	</td>
</tr>
</table>
<br />
<table class="tbl-list tbpadd" width="100%" border="1">
	<tr>
		<td width="5%" class="td-label" style="text-align:center">
			<b>#</b>
		</td>
		<td width="30%" class="td-label">
			<b><?php echo $lang['name']?></b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo $lang['money_ad']?> (VND)</b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo $lang['money_sub']?> (VND)</b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo $lang['money_promotion']?> (VND)</b>
		</td>
	</tr>
	<?php
	$i = 0;
	$tmpIndexGroup = -10;
	foreach ($items as $item){
		if($item->typegroup != $tmpIndexGroup)	//Bat dau 1 group
		{
			$tmpIndexGroup = $item->typegroup;
			$i = 0;
	?>
	<tr style="background:#d6d6d6;font-weight:bold;">
		<td colspan="2"><?php echo ($item->typegroup == 1 ? 'Nội bộ' : ($item->typegroup == 2 ? 'Khách hàng' : 'Other'));?></td>
		<td class="text-right">
			<?php echo number_format($totalForGroup[$tmpIndexGroup]['ad']);?>
		</td>
		<td class="text-right">
			<?php echo number_format($totalForGroup[$tmpIndexGroup]['sub']);?>
		</td>
		<td class="text-right">
			<?php echo number_format($totalForGroup[$tmpIndexGroup]['promotion']);?>
		</td>
	</tr>
	<?php } $i++; ?>
	<tr class="row">
		<td style="text-align:center">
			<?php echo $i;?>
		</td>
		<td>
			<a href="javascript:void(0);" onclick="getBudget(<?php echo $item->id;?>);">
				<?php echo $item->username;?>
			</a>
		</td>
		<td style="text-align:right">
			<?php echo number_format($item->ad);?>
		</td>
		<td style="text-align:right">
			<?php echo number_format($item->sub);?>
		</td>
		<td style="text-align:right">
			<?php echo number_format($item->promotion);?>
		</td>
	</tr>
	<?php }?>
	<tr>
		<td colspan="2" class="td-label" style="text-align:right">
			<b><?php echo $lang['sum'];?>:</b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo number_format($summary->ad);?></b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo number_format($summary->sub);?></b>
		</td>
		<td class="td-label" style="text-align:right">
			<b><?php echo number_format($summary->promotion);?></b>
		</td>
	</tr>
</table>
<div style="clear:both; height:10px;"><span></span></div>
<div id="budgetChart1" class="chart"></div>
<div style="clear:both; height:10px;"><span></span></div>
<div id="budgetChart2" class="chart"></div>
<script language="javascript">
	var addCommasNumber=function addCommas(nStr)
	{
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}
	<?php if(isset($chart1->label) && count($chart1->label) > 0){?>
	   var chart1 = new Highcharts.Chart({
	      chart: {
	         renderTo: 'budgetChart1',
	         defaultSeriesType: 'spline'
	      },
	      title: {
	         text: 'Báo cáo tài chính (từ <?php echo date('d/m/Y', strtotime($startdate));?> đến <?php echo date('d/m/Y', strtotime($enddate));?>)'
	      },
	      subtitle: {
	         text: ''
	      },
	      xAxis: {
	         categories: ['<?php echo implode("','", $chart1->label);?>'],
	         tickInterval: <?php $step = (int)(count($chart1->label)/4); echo ($step > 0 ? $step : 1);?>,
			     gridLineWidth: 0
		      },
		      yAxis: {
		         title: {
		            text: 'Tài chính'
		         },
		         labels: {
		            formatter: function() {
		               return addCommasNumber(this.value)
		            }
		         },
		         min: 0
		      },
		      tooltip: {
		         crosshairs: true,
		         shared: true,
		         formatter: function()
		         {
		             var s = '<b>Ngày '+ this.x +'</b>';
		             $.each(this.points, function(i, point) {
		                 s += '<br/>'+ point.series.name +': '+addCommasNumber(point.y)+' đ';
		             });
		             
		             return s;
		         }
		      },
		      plotOptions: {
	            spline: {
	               marker: {
	                  enable: false
	               }
	            }
	         },
	      series: [{
	         name: 'Đã nạp',
	         data: [<?php echo implode(',', $chart1->ad);?>]
	      }, {
	         name: 'Đã tiêu',
	         data: [<?php echo implode(',', $chart1->sub);?>]
	      }, {
	         name: 'Khuyễn mãi',
	         data: [<?php echo implode(',', $chart1->promotion);?>]
	      }],
	      exporting: {
	          enabled: false
	      }
	   });
	   <?php } else {?>
		$('#budgetChart1').html('Chưa có dữ liệu trả về');
	   <?php }?>
	   <?php if(isset($chart2->label) && count($chart2->label) > 0){?>
	   var chart11 = new Highcharts.Chart({
	      chart: {
	         renderTo: 'budgetChart2',
	         defaultSeriesType: 'spline'
	      },
	      title: {
	         text: 'Báo cáo so sánh Tiền đã tiêu - Tiền tính theo clickCharge (từ <?php echo date('d/m/Y', strtotime($startdate));?> đến <?php echo date('d/m/Y', strtotime($enddate));?>)'
	      },
	      subtitle: {
	         text: ''
	      },
	      xAxis: {
	         categories: ['<?php echo implode("','", $chart2->label);?>'],
	         tickInterval: <?php $step = (int)(count($chart2->label)/4); echo ($step > 0 ? $step : 1);?>,
			     gridLineWidth: 0
		      },
		      yAxis: {
		         title: {
		            text: 'Tiền đã tiêu & Tiền clickCharge'
		         },
		         labels: {
		            formatter: function() {
		               return addCommasNumber(this.value)
		            }
		         },
		         min: 0
		      },
		      tooltip: {
		         crosshairs: true,
		         shared: true,
		         formatter: function()
		         {
		             var s = '<b>Ngày '+ this.x +'</b>';
		             $.each(this.points, function(i, point) {
		                 s += '<br/>'+ point.series.name +': '+addCommasNumber(point.y)+' đ';
		             });
		             
		             return s;
		         }
		      },
		      plotOptions: {
	            spline: {
	               marker: {
	                  enable: false
	               }
	            }
	         },
	      series: [{
	         name: 'Tiền theo Clicks',
	         data: [<?php echo implode(',', $chart2->money_click_charge);?>]
	      }, {
	         name: 'Tiền đã tiêu',
	         data: [<?php echo implode(',', $chart2->money_use);?>]
	      }],
	      exporting: {
	          enabled: false
	      }
	   });
	   <?php } else {?>
		$('#budgetChart2').html('Chưa có dữ liệu trả về');
	   <?php }?>
<?php }?>